/*
 * @Author: 恒恒 1067531094@qq.com
 * @Date: 2022-10-12 17:17:17
 * @LastEditors: 恒恒 1067531094@qq.com
 * @LastEditTime: 2022-10-13 20:02:02
 * @FilePath: \作业\router\regRouter.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
const express = require('express')
const router = express.Router()

const fs = require('fs')
let persons = fs.readFileSync(__dirname + "/persons.json", "utf8");
persons = JSON.parse(persons);

router.get('/reg', (req, res) => {
    res.render('register.html')
})

router.post('/reg', (req, res) => {
    let { tel, pass, pass2 } = req.body
    let p = persons.find((item) => {
        console.log(item)
        return item.username == tel && item.password == pass && item.password == pass2
    })

    if (p) {
        res.send('已注册，请登录')
    }
    else {
        res.send('注册成功')
    }
})
module.exports = router